const app = getApp()
Component({
  properties: {
    headlineData: {
      type: Array,
      value: []
    }
  },

  data: {
    imgUrl: app.globalData.imgUrl,
    current: 0
  },

  attached() { 
    this.handler = setInterval(() => {
      const current = this.data.current || 0;
      this.setData({
        current: (current + 1) % this.data.headlineData.length
      });
    }, 3000);
  },

  detached() {
    clearInterval(this.handler);
  },

  methods: {
    toNewsDetail(e) {
      const { id } = e.currentTarget.dataset;
      wx.navigateTo({
        url: "/pages/news/newsDetail?newsId=" + id
      });
    }
  }
});
